﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using FOModels.AccumulateDeposit;
using DataAccess.AccumulateDeposit;
using System.Net;
namespace Bussiness.AccumulateDeposit
{
    public class AccumulateDepositBLL
    {
        private AccumulateDepositDAL dal;

        public AccumulateDepositBLL()
        {
            dal = new AccumulateDepositDAL();
        }
        public int UpdateStatus(AccumulateDepositApplyModels card)
        {
            if (dal.UpdateStatus(card) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int DeleteAccumulateDepositApply(int SavingDepositApplyID)
        {
            if (dal.DeleteAccumulateDepositApply(SavingDepositApplyID) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int AccumulateDepositApply(int DepositSavingID, AccumulateDepositApplyModels card)
        {
            if (dal.AccumulateDepositApply(DepositSavingID, card) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public AccumulateDepositApplyModels getcontractbyid(int cardapplyid)
        {

            AccumulateDepositApplyModels fur = new AccumulateDepositApplyModels();
            DataTable tb = dal.getcontractbyid(cardapplyid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new AccumulateDepositApplyModels();
                    fur.AccumulateDepositApplyID = int.Parse(row["AccumulateDepositApplyID"].ToString());
                    fur.AccumulateDepositID = int.Parse(row["AccumulateDepositID"].ToString());
                    fur.CustomerName = row["CustomerName"].ToString();
                    fur.CustomerEmail = row["CustomerEmail"].ToString();
                    fur.CustomerPhone = row["CustomerPhone"].ToString();
                    fur.CustomerIncome = row["CustomerIncome"].ToString();
                    fur.CustomerDOB = row["CustomerDOB"].ToString();
                    fur.StatusID = int.Parse(row["StatusID"].ToString());
                    fur.AppDate = row["AppDate"].ToString();
                    fur.AccumulateDepositName = row["AccumulateDepositName"].ToString();
                    fur.CompanyImg = row["CompanyLogo"].ToString();
                    fur.CompanyName = row["Name"].ToString();
                    fur.StatusName = row["StatusName"].ToString();
                }
            }
            return fur;
        }
        public List<AccumulateDepositApplyModels> getcontract()
        {
            List<AccumulateDepositApplyModels> list = new List<AccumulateDepositApplyModels>();
            AccumulateDepositApplyModels fur;
            DataTable tb = dal.getcontract();
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new AccumulateDepositApplyModels();
                    fur.AccumulateDepositApplyID = int.Parse(row["AccumulateDepositApplyID"].ToString());
                    fur.AccumulateDepositID = int.Parse(row["AccumulateDepositID"].ToString());
                    fur.CustomerName = row["CustomerName"].ToString();
                    fur.CustomerEmail = row["CustomerEmail"].ToString();
                    fur.CustomerPhone = row["CustomerPhone"].ToString();
                    fur.CustomerIncome = row["CustomerIncome"].ToString();
                    fur.CustomerDOB = row["CustomerDOB"].ToString();
                    fur.StatusID = int.Parse(row["StatusID"].ToString());
                    fur.AppDate = row["AppDate"].ToString();
                    fur.AccumulateDepositName = row["AccumulateDepositName"].ToString();
                    fur.CompanyImg = row["CompanyLogo"].ToString();
                    fur.CompanyName = row["Name"].ToString();
                    fur.StatusName = row["StatusName"].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<AccumulateDepositApplyModels> getcontractbystatus(int statusid)
        {
            List<AccumulateDepositApplyModels> list = new List<AccumulateDepositApplyModels>();
            AccumulateDepositApplyModels fur;
            DataTable tb = dal.getcontractbystatus(statusid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new AccumulateDepositApplyModels();
                    fur.AccumulateDepositApplyID = int.Parse(row["AccumulateDepositApplyID"].ToString());
                    fur.AccumulateDepositID = int.Parse(row["AccumulateDepositID"].ToString());
                    fur.CustomerName = row["CustomerName"].ToString();
                    fur.CustomerEmail = row["CustomerEmail"].ToString();
                    fur.CustomerPhone = row["CustomerPhone"].ToString();
                    fur.CustomerIncome = row["CustomerIncome"].ToString();
                    fur.CustomerDOB = row["CustomerDOB"].ToString();
                    fur.StatusID = int.Parse(row["StatusID"].ToString());
                    fur.AppDate = row["AppDate"].ToString();
                    fur.AccumulateDepositName = row["AccumulateDepositName"].ToString();
                    fur.CompanyImg = row["CompanyLogo"].ToString();
                    fur.CompanyName = row["Name"].ToString();
                    fur.StatusName = row["StatusName"].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<AccumulateDepositModels> getAccumulateDepositDefalt(int langid)
        {
            List<AccumulateDepositModels> list = new List<AccumulateDepositModels>();
            AccumulateDepositModels fur;
            DataTable tb = dal.getAccumulateDepositDefalt(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new AccumulateDepositModels();
                    fur.AccumulateDepositID = int.Parse(row["AccumulateDepositID"].ToString());
                    fur.AccumulateDepositName = row["AccumulateDepositName"].ToString();
                    fur.Benefit = WebUtility.HtmlDecode(row["Benefit"].ToString());
                    fur.CompanyID = int.Parse(row["CompanyID"].ToString());
                    fur.InterestRate = float.Parse(row["InterestRate"].ToString());
                    fur.MinTermDepositBalance = String.Format("{0:0,0}", double.Parse(row["MinTermDepositBalance"].ToString())).Replace(',', '.');
                    fur.MaxTermDepositBalance = String.Format("{0:0,0}", double.Parse(row["MaxTermDepositBalance"].ToString())).Replace(',', '.');
                    fur.Description = WebUtility.HtmlDecode(row["Description"].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row["FeeContent"].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row["MoreInfo"].ToString());
                    fur.Display = bool.Parse(row["Display"].ToString());
                    fur.CompanyName = row["Name"].ToString();
                    fur.CompanyImg = row["CompanyLogo"].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<AccumulateDepositModels> getAccumulatedSavingDefaultByProvider(int CompanyID, int langid)
        {
            List<AccumulateDepositModels> list = new List<AccumulateDepositModels>();
            AccumulateDepositModels fur;
            DataTable tb = dal.getAccumulatedSavingDefaultByProvider(CompanyID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new AccumulateDepositModels();
                    fur.AccumulateDepositID = int.Parse(row["AccumulateDepositID"].ToString());
                    fur.AccumulateDepositName = row["AccumulateDepositName"].ToString();
                    fur.Benefit = WebUtility.HtmlDecode(row["Benefit"].ToString());
                    fur.CompanyID = int.Parse(row["CompanyID"].ToString());
                    fur.InterestRate = float.Parse(row["InterestRate"].ToString());
                    fur.MinTermDepositBalance = String.Format("{0:0,0}", double.Parse(row["MinTermDepositBalance"].ToString())).Replace(',', '.');
                    fur.MaxTermDepositBalance = String.Format("{0:0,0}", double.Parse(row["MaxTermDepositBalance"].ToString())).Replace(',', '.');
                    fur.Description = WebUtility.HtmlDecode(row["Description"].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row["FeeContent"].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row["MoreInfo"].ToString());
                    fur.Display = bool.Parse(row["Display"].ToString());
                    fur.CompanyName = row["Name"].ToString();
                    fur.CompanyImg = row["CompanyLogo"].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<AccumulateDepositModels> getAccumulateDepositList(string termbalance, int langid)
        {
            List<AccumulateDepositModels> list = new List<AccumulateDepositModels>();
            AccumulateDepositModels fur;
            DataTable tb = dal.getAccumulateDepositList(termbalance, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new AccumulateDepositModels();
                    fur.AccumulateDepositID = int.Parse(row["AccumulateDepositID"].ToString());
                    fur.AccumulateDepositName = row["AccumulateDepositName"].ToString();
                    fur.Benefit = WebUtility.HtmlDecode(row["Benefit"].ToString());
                    fur.CompanyID = int.Parse(row["CompanyID"].ToString());
                    fur.InterestRate = float.Parse(row["InterestRate"].ToString());
                    fur.MinTermDepositBalance = String.Format("{0:0,0}", double.Parse(row["MinTermDepositBalance"].ToString())).Replace(',', '.');
                    fur.MaxTermDepositBalance = String.Format("{0:0,0}", double.Parse(row["MaxTermDepositBalance"].ToString())).Replace(',', '.');
                    fur.Description = WebUtility.HtmlDecode(row["Description"].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row["FeeContent"].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row["MoreInfo"].ToString());
                    fur.Display = bool.Parse(row["Display"].ToString());
                    fur.CompanyName = row["Name"].ToString();
                    fur.CompanyImg = row["CompanyLogo"].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<AccumulateDepositModels> getAccumulateDepositListByProvider(string termbalance, int CompanyID, int langid)
        {
            List<AccumulateDepositModels> list = new List<AccumulateDepositModels>();
            AccumulateDepositModels fur;
            DataTable tb = dal.getAccumulateDepositListByProvider(termbalance, CompanyID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new AccumulateDepositModels();
                    fur.AccumulateDepositID = int.Parse(row["AccumulateDepositID"].ToString());
                    fur.AccumulateDepositName = row["AccumulateDepositName"].ToString();
                    fur.Benefit = WebUtility.HtmlDecode(row["Benefit"].ToString());
                    fur.CompanyID = int.Parse(row["CompanyID"].ToString());
                    fur.InterestRate = float.Parse(row["InterestRate"].ToString());
                    fur.MinTermDepositBalance = String.Format("{0:0,0}", double.Parse(row["MinTermDepositBalance"].ToString())).Replace(',', '.');
                    fur.MaxTermDepositBalance = String.Format("{0:0,0}", double.Parse(row["MaxTermDepositBalance"].ToString())).Replace(',', '.');
                    fur.Description = WebUtility.HtmlDecode(row["Description"].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row["FeeContent"].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row["MoreInfo"].ToString());
                    fur.Display = bool.Parse(row["Display"].ToString());
                    fur.CompanyName = row["Name"].ToString();
                    fur.CompanyImg = row["CompanyLogo"].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<AccumulateDepositModels> getaccumulatedsavingrelati(int CompanyID, int AccumulateDepositID, int langid)
        {
            List<AccumulateDepositModels> list = new List<AccumulateDepositModels>();
            AccumulateDepositModels fur;
            DataTable tb = dal.getaccumulatedsavingrelati(CompanyID, AccumulateDepositID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new AccumulateDepositModels();
                    fur.AccumulateDepositID = int.Parse(row["AccumulateDepositID"].ToString());
                    fur.AccumulateDepositName = row["AccumulateDepositName"].ToString();
                    fur.Benefit = WebUtility.HtmlDecode(row["Benefit"].ToString());
                    fur.CompanyID = int.Parse(row["CompanyID"].ToString());
                    fur.InterestRate = float.Parse(row["InterestRate"].ToString());
                    fur.MinTermDepositBalance = String.Format("{0:0,0}", double.Parse(row["MinTermDepositBalance"].ToString())).Replace(',', '.');
                    fur.MaxTermDepositBalance = String.Format("{0:0,0}", double.Parse(row["MaxTermDepositBalance"].ToString())).Replace(',', '.');
                    fur.Description = WebUtility.HtmlDecode(row["Description"].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row["FeeContent"].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row["MoreInfo"].ToString());
                    fur.Display = bool.Parse(row["Display"].ToString());
                    fur.CompanyName = row["Name"].ToString();
                    fur.CompanyImg = row["CompanyLogo"].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public AccumulateDepositModels getAccumulateDepositByID(int AccumulateDepositID, int langid)
        {
            AccumulateDepositModels fur = new AccumulateDepositModels();
            DataTable tb = dal.getAccumulateDepositByID(AccumulateDepositID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new AccumulateDepositModels();
                    fur.AccumulateDepositID = int.Parse(row["AccumulateDepositID"].ToString());
                    fur.AccumulateDepositName = row["AccumulateDepositName"].ToString();
                    fur.Benefit = WebUtility.HtmlDecode(row["Benefit"].ToString());
                    fur.CompanyID = int.Parse(row["CompanyID"].ToString());
                    fur.InterestRate = float.Parse(row["InterestRate"].ToString());
                    fur.MinTermDepositBalance = String.Format("{0:0,0}", double.Parse(row["MinTermDepositBalance"].ToString())).Replace(',', '.');
                    fur.MaxTermDepositBalance = String.Format("{0:0,0}", double.Parse(row["MaxTermDepositBalance"].ToString())).Replace(',', '.');
                    fur.Description = WebUtility.HtmlDecode(row["Description"].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row["FeeContent"].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row["MoreInfo"].ToString());
                    fur.Display = bool.Parse(row["Display"].ToString());
                    fur.CompanyName = row["Name"].ToString();
                    fur.CompanyImg = row["CompanyLogo"].ToString();
                }
            }
            return fur;
        }
        public AccumulateDepositModels getAccumulateDepositByIDManager(int AccumulateDepositID, int langid)
        {
            AccumulateDepositModels fur = new AccumulateDepositModels();
            DataTable tb = dal.getAccumulateDepositByIDManager(AccumulateDepositID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new AccumulateDepositModels();
                    fur.AccumulateDepositID = int.Parse(row["AccumulateDepositID"].ToString());
                    fur.AccumulateDepositName = row["AccumulateDepositName"].ToString();
                    fur.Benefit = WebUtility.HtmlDecode(row["Benefit"].ToString());
                    fur.CompanyID = int.Parse(row["CompanyID"].ToString());
                    fur.InterestRate = float.Parse(row["InterestRate"].ToString());
                    fur.MinTermDepositBalance = String.Format("{0:0,0}", double.Parse(row["MinTermDepositBalance"].ToString())).Replace(',', '.');
                    fur.MaxTermDepositBalance = String.Format("{0:0,0}", double.Parse(row["MaxTermDepositBalance"].ToString())).Replace(',', '.');
                    fur.Description = WebUtility.HtmlDecode(row["Description"].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row["FeeContent"].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row["MoreInfo"].ToString());
                    fur.Display = bool.Parse(row["Display"].ToString());
                    fur.CompanyName = row["Name"].ToString();
                    fur.CompanyImg = row["CompanyLogo"].ToString();
                }
            }
            return fur;
        }
        public AccumulateDepositModels getTOP1()
        {
            AccumulateDepositModels fur = new AccumulateDepositModels();
            DataTable tb = dal.getTOP1();
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new AccumulateDepositModels();
                    fur.AccumulateDepositID = int.Parse(row["AccumulateDepositID"].ToString());
                }
            }
            return fur;
        }
        public List<AccumulateDepositModels> getall(int langid)
        {
            List<AccumulateDepositModels> list = new List<AccumulateDepositModels>();
            AccumulateDepositModels fur;
            DataTable tb = dal.getall(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new AccumulateDepositModels();
                    fur.AccumulateDepositID = int.Parse(row["AccumulateDepositID"].ToString());
                    fur.AccumulateDepositName = row["AccumulateDepositName"].ToString();
                    fur.Benefit = WebUtility.HtmlDecode(row["Benefit"].ToString());
                    fur.CompanyID = int.Parse(row["CompanyID"].ToString());
                    fur.InterestRate = float.Parse(row["InterestRate"].ToString());
                    fur.MinTermDepositBalance = row["MinTermDepositBalance"].ToString();
                    fur.MaxTermDepositBalance = row["MaxTermDepositBalance"].ToString();
                    fur.Description = WebUtility.HtmlDecode(row["Description"].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row["FeeContent"].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row["MoreInfo"].ToString());
                    fur.Display = bool.Parse(row["Display"].ToString());
                    fur.CompanyName = row["Name"].ToString();
                    fur.CompanyImg = row["CompanyLogo"].ToString();
                    fur.FlagImage = row["FlagImage"].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public int UpdateAccumulateDeposit(AccumulateDepositModels models, int langid)
        {
            if (dal.UpdateAccumulateDeposit(models) > 0 && dal.UpdateAccumulateDepositLang(models, langid) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int InsertAccumulateDeposit(AccumulateDepositModels models)
        {
            if (dal.InsertAccumulateDeposit(models) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int InsertAccumulateDepositLang(AccumulateDepositModels models, int langid)
        {
            if (dal.InsertAccumulateDepositLang(models, langid) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int DeleteAccumulateDeposit(int AccumulateDepositID)
        {
            if (dal.DeleteAccumulateDepositLang(AccumulateDepositID) > 0 && dal.DeleteAccumulateDeposit(AccumulateDepositID) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }

    }
}
